package com.xfly.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ptmall.app.R;
import com.ptmall.app.bean.OrderBean;
import com.ptmall.app.ui.adapter.OrderGoodAdapter;
import com.ptmall.app.utils.GlideUtil;
import com.ptmall.app.utils.TimeUtil;
import com.ptmall.app.view.NoScrollListView;

import java.util.List;


/**
 * Created by Administrator on 2018/1/12.
 */

public class OffLineOrderListAdapter extends BaseAdapter {

    private Context mContext;
    private List<OrderBean> mDataList;
    private LayoutInflater mLayoutInflater;
    private OrderGoodAdapter mOrderGoodAdapter;


    ClickInterface clickInterface;


    public void setClickInterface(ClickInterface clickInterface) {
        this.clickInterface = clickInterface;
    }


    public OffLineOrderListAdapter(Context context, List<OrderBean> list) {
        this.mContext = context;
        this.mDataList = list;
        this.mLayoutInflater = LayoutInflater.from(mContext);
    }

    public void pushData(List<OrderBean> list) {
        this.mDataList = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (mDataList == null) {
            return 0;
        }
        return mDataList.size();
    }


    @Override
    public Object getItem(int position) {
        return mDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (null == convertView) {
            convertView = mLayoutInflater.inflate(R.layout.item_xforder, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        OrderBean bean = mDataList.get(position);
        mOrderGoodAdapter = new OrderGoodAdapter(mContext, bean.goods);
        viewHolder.goodlist.setAdapter(mOrderGoodAdapter);

        GlideUtil.showImg(mContext,bean.member.avatar,viewHolder.toppic);

        viewHolder.namephone.setText(bean.member.name+"  "+bean.member.phone);
        viewHolder.address.setText(bean.member.address);

        viewHolder.total.setText("共"+bean.count+"件商品，合计：¥"+bean.price);
        viewHolder.ordertime.setText(TimeUtil.getStrTime(bean.create_time+""));

        viewHolder.btn_lin.setVisibility(View.GONE);

        return convertView;
    }

    class ViewHolder {

        ImageView toppic;
        NoScrollListView goodlist;
        TextView namephone, address,ordertime,total,status,status_btn,call,jj,ty;
        LinearLayout button_lin,btn_lin;
        Button btn2;


        ViewHolder(View view) {
            goodlist = (NoScrollListView) view.findViewById(R.id.goodlist);
            address = (TextView) view.findViewById(R.id.address);
            namephone = (TextView) view.findViewById(R.id.namephone);
            button_lin = (LinearLayout) view.findViewById(R.id.button_lin);
            status_btn =  view.findViewById(R.id.status_btn);
            toppic = view.findViewById(R.id.toppic);
            ordertime = view.findViewById(R.id.ordertime);
            total = view.findViewById(R.id.total);
            status = view.findViewById(R.id.status);
            call = view.findViewById(R.id.call);
            jj = view.findViewById(R.id.jj);
            ty = view.findViewById(R.id.ty);
            btn_lin = view.findViewById(R.id.btn_lin);
        }
    }


    public interface ClickInterface {
        void btn1Click(String status, OrderBean bean);

        void btn2Click(String id, int position, String status, OrderBean bean);
    }


}
